//
//  InfoCell.m
//  Shengzhuli
//
//  Created by subook on 16/9/6.
//  Copyright © 2016年 kamangkeji. All rights reserved.
//

#import "InfoCell.h"
#import "QiHuoCell.h"

@interface InfoCell ()<UICollectionViewDelegate,UICollectionViewDataSource>

@property (weak, nonatomic) IBOutlet UILabel *nickNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *sexLabel;
@property (weak, nonatomic) IBOutlet UILabel *ageLabel;
@property (weak, nonatomic) IBOutlet UILabel *wineAgeLabel;
@property (weak, nonatomic) IBOutlet UILabel *personNoteLabel;
@property (weak, nonatomic) IBOutlet UICollectionView *wineCollectionView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *collectionHeightCons;

@end

@implementation InfoCell

- (void)awakeFromNib
{
    [super awakeFromNib];
    UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init];
    CGFloat width = (ScreenW-15*5)/4.0;
    flow.itemSize = CGSizeMake(width, width+20+5);
    flow.minimumInteritemSpacing = 15;
    flow.minimumLineSpacing = 0;
    self.wineCollectionView.collectionViewLayout = flow;
    self.wineCollectionView.delegate = self;
    self.wineCollectionView.dataSource = self;
    [self.wineCollectionView registerNib:[UINib nibWithNibName:NSStringFromClass([QiHuoCell class]) bundle:nil] forCellWithReuseIdentifier:NSStringFromClass([QiHuoCell class])];
    
    self.collectionHeightCons.constant = WineCollectionHeight;
}
- (void)setModel:(FriendsDetailModel *)model
{
    _model = model;
    self.nickNameLabel.text = model.nickName;
    NSString *sex;
    if (model.gender == 0) {
        sex = @"不详";
    }else if (model.gender == 1){
        sex = @"男";
    }else{
        sex = @"女";
    }
    self.sexLabel.text = sex;
    self.ageLabel.text = [NSString stringWithFormat:@"%zd",model.age];
    self.wineAgeLabel.text = [NSString stringWithFormat:@"%zd",model.registerAge];
    self.personNoteLabel.text = model.personalizedSignature;
    [self.wineCollectionView reloadData];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.model.futures.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{    
    QiHuoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([QiHuoCell class]) forIndexPath:indexPath];
    cell.model = self.model.futures[indexPath.row];
    return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"indexPath = %@",indexPath);
}
@end
